﻿package {
	import flash.xml.*;

	import flash.events.Event;

	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLVariables;
	import flash.net.URLRequestMethod;
	public class LoadStyle {
		private var style:XML;

		private var defaultStyle:XML;
		private var loader:URLLoader;//
		private var url:URLRequest;//
		private var flag:Boolean;
		public function LoadStyle() {
			//this.style=new Array();
			setDefaultStyle();
			flag=false;
			//url=new URLRequest("http://127.0.0.1/languagenuts/style.xml.php");//从datatoflash这个中获得数据。
			url=new URLRequest("http://192.168.1.200/ZS/style.xml.php"); //从datatoflash这个中获得数据。

			url.method=URLRequestMethod.POST;//用post方法传递参数
			loader = new URLLoader();
			//监听数载加载完成事件 
			//loader.dataFormat = URLLoaderDataFormat.VARIABLES;
			//事件相应函数 
			var values:URLVariables = new URLVariables();//设置传递的参数属性
			values.message="";//参数名message，值s
			url.data=values;//
			cwpLoad();
		}
		private function setDefaultStyle() {
			this.defaultStyle=
			<root>
			<words totle="2">			
				<mainSprite>
					<mid-lineX>480</mid-lineX>
					<y>132</y>
				</mainSprite>
				<smallRect>
					<width>175</width>
					<y>35</y>
				</smallRect>
				<midRect>
					<width>210</width>
					<y>15</y>
				</midRect>			
				<characterFrame>
					<width>350</width>
					<y>0</y>
					<cover-left>0.1</cover-left>
					<cover-right>0.1</cover-right>
					<borderShape>
						<width>5</width>
						<color>0xC6EFCE</color>
					</borderShape>
					<hintButton>
						<x>-55</x>
						<y>25</y>
					</hintButton>
					<learnButton>
						<x>-55</x>
						<y>70</y>
					</learnButton>
					<filterSprite>
						<scaleX>0.9</scaleX>
						<scaleY>0.9</scaleY>
					</filterSprite>
					<graphics>
						<lineWidth>2</lineWidth>
						<color>0x000000</color>
					</graphics>
					<hintSprite>
						<inNormalCharacterFrame>
							<scaleX>0.9</scaleX>
							<scaleX>0.9</scaleX>
						</inNormalCharacterFrame>
						<inSmallCharacterFrame>
							<scaleX>0.8</scaleX>
							<scaleX>0.8</scaleX>
						</inSmallCharacterFrame>
					</hintSprite>	
				</characterFrame>
				<learnSprite>
					<border-width>1</border-width>
					<border-color>0x000000</border-color>
					<fill-color>0xdddddd</fill-color>
					<width>250</width>
					<height>210</height>
					<move-left>120</move-left>
					<move-left-speed>10</move-left-speed>
					<move-down-speed>0.03</move-down-speed>
					<fillSprite>
						<x>25</x>
						<y>50</y>
						<strokeShapeScale>0.33</strokeShapeScale>
						<fillSpeed>50</fillSpeed>
					</fillSprite>
				</learnSprite>
			</words>			
			<words totle="3">
			3
			</words>			
			<words totle="4">
			4			
			</words>
		</root>;
		}

		function getFlag():Boolean {
			return this.flag;
		}
		function loaded(e:Event) {
			try {
				this.style=new XML(loader.data);
				this.flag=true;
				
			} catch (errObject:Error) {
				trace(errObject.message);
				trace('load failed!------------------------>');
			}
		}
		public function getLoadedStyle():XML {
			if (this.style) {
				return this.style;
			} else {
				return this.defaultStyle;
			}
		}
		public function cwpLoad() {

			loader.addEventListener(Event.COMPLETE,loaded);//添加load事件
			try {
				loader.load(url);
			} catch (errObject:Error) {
				trace(errObject.message);
				trace('load failed!-------------------------------->');
			}

		}

	}
}